package es.franciscovargas.buscalabs;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class BuscaLabsEPSActivity extends Activity {
	Context c;
	final static int horacerrar = 20;
	final static int horaabrir = 9;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		c = this;
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		final Button laboslibres = (Button) findViewById(R.id.laboslibres);

		laboslibres.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				final GregorianCalendar calendar = new GregorianCalendar();
				calendar.setTimeZone(TimeZone.getTimeZone("Europe/Madrid"));
				final int diasemana = calendar.get(Calendar.DAY_OF_WEEK);
				final int hora = calendar.get(Calendar.HOUR_OF_DAY);

				if (diasemana == Calendar.SATURDAY
						|| diasemana == Calendar.SUNDAY
						|| hora >= horacerrar
						|| hora < horaabrir)
				{
					Toast.makeText(c, R.string.textoerrorhoras, 2500).show();
				}
				else 
				{
					Intent lista = new Intent(c, ListaLabos.class);
					startActivity(lista);
				}

			}
		});
	}

}
